import React from 'react'
import { useSearchParams } from 'react-router-dom'

export default function TestQuery() {
    let [query, setQuery] = useSearchParams()
    let username = query.get('username')
    let age = query.get('age')

    return (
        <div>
            <h3>TestQuery</h3>
            <p>username: {username}</p>
            <p>age: {age}</p>
            <p><button onClick={()=>{
                // 方式一：字符串
                // setQuery('username=尚硅谷&age=99')
                // 方式二：对象写法
                setQuery({
                    username:'尚硅谷',
                    age:199
                })
            }}>设置query参数</button></p>
        </div>
    )
}
